#include "stdafx.h"
#include "IResCfg.h"
#include "MyUnCompress.h"
#include "debug_new.h"


CIResCfg::CIResCfg( ):CResConfig( )
{
}

CIResCfg::~CIResCfg(void)
{
}

BOOL CIResCfg::LoadIBtnParam(IBtnInfo &btnInfo,wstring strkey)
{
	btnInfo.m_rc.SetRectEmpty();
	m_xml.ResetMainPos();
	btnInfo.m_strImgNor.empty();
	btnInfo.m_strImgAct.empty();
	btnInfo.m_strImgDisable.empty();

	if(m_xml.FindChildElem(strkey))
	{
		btnInfo.m_strImgNor = m_xml.GetChildAttrib(L"IMAGE");
		btnInfo.m_strImgAct = m_xml.GetChildAttrib(L"IMGACT");
		btnInfo.m_strImgDisable = m_xml.GetChildAttrib(L"IMGDSA");
		
		wstring strTmp = m_xml.GetChildAttrib(L"RECT");
		btnInfo.m_rc = GetRectFromString(strTmp);

		strTmp = m_xml.GetChildAttrib(L"NTC");
		btnInfo.m_clrTxtNormal = GetColorFromString(strTmp);

		strTmp = m_xml.GetChildAttrib(L"ATC");
		btnInfo.m_clrTxtActive = GetColorFromString(strTmp);

		strTmp  = m_xml.GetChildAttrib(L"TOS");
		btnInfo.m_szTxtOffset = GetSizeFormString(strTmp);

		//strTmp  = m_xml.GetChildAttrib(L"BETRANS");
		//if(strTmp != L"0")
		//	btnInfo.m_bTranparent = TRUE;
		//else
		//	btnInfo.m_bTranparent = FALSE;

		//strTmp = m_xml.GetChildAttrib(L"TCOLOR");
		//btnInfo.m_clrTranparent = GetColorFromString(strTmp);

		strTmp = m_xml.GetChildAttrib(L"ALIGN");
		btnInfo.m_dwAlign = _wtoi(strTmp.c_str());

		btnInfo.m_strFont = m_xml.GetChildAttrib(L"FONT");
	}
	else
	{
		return FALSE;
	}

	return TRUE;
}

BOOL CIResCfg::ReInitFAlpBtn( CFAlpResBtn *pBtn ,IBtnInfo &btnInfo )
{
	FONT_DECLARE;
	if(NULL == pBtn)
		return FALSE;
	
	pBtn->LoadStateRes( m_strResPath+btnInfo.m_strImgNor,STBTN_NOR );
	pBtn->LoadStateRes( m_strResPath+btnInfo.m_strImgAct,STBTN_ACT );
	pBtn->LoadStateRes( m_strResPath+btnInfo.m_strImgDisable,STBTN_DISABLE );

	pBtn->SetTextOffset(btnInfo.m_szTxtOffset);
	pBtn->SetTxtNormal(btnInfo.m_clrTxtNormal);
	pBtn->SetTxtActive(btnInfo.m_clrTxtActive);
	pBtn->SetAlign(btnInfo.m_dwAlign);
	pBtn->SetFont(FNT_GETFONT(btnInfo.m_strFont));

}

BOOL CIResCfg::ReInitFAlpBtn( CFAlpResBtn *pBtn ,IBtnInfo &btnInfo ,CMyUnCompress* pPack )
{
	if ( pPack==NULL )
		return ReInitFAlpBtn( pBtn ,btnInfo );
	
	FONT_DECLARE;
	pBtn->LoadStateRes( btnInfo.m_strImgNor,STBTN_NOR, pPack );
	pBtn->LoadStateRes( btnInfo.m_strImgAct,STBTN_ACT, pPack );
	pBtn->LoadStateRes( btnInfo.m_strImgDisable,STBTN_DISABLE, pPack );

	pBtn->SetTextOffset(btnInfo.m_szTxtOffset);
	pBtn->SetTxtNormal(btnInfo.m_clrTxtNormal);
	pBtn->SetTxtActive(btnInfo.m_clrTxtActive);
	pBtn->SetAlign(btnInfo.m_dwAlign);
	pBtn->SetFont(FNT_GETFONT(btnInfo.m_strFont));

}

BOOL CIResCfg::GetTimeNumParam(  ITimeNumInfo &btnInfo,wstring strkey)
{
	m_xml.ResetMainPos();
	btnInfo.m_rc.SetRectEmpty();
	if(m_xml.FindChildElem(strkey))
	{
		wstring strTmp = m_xml.GetChildAttrib(L"IMAGE");
		if(!strTmp.length())
		{
			return FALSE;
		}
		else
		{
			btnInfo.m_strImg = strTmp;
		}

		strTmp = m_xml.GetChildAttrib(L"RECT");
		btnInfo.m_rc = GetRectFromString(strTmp);

		btnInfo.m_bTranparent = FALSE;
		strTmp  = m_xml.GetChildAttrib(L"BETRANS");
		if(strTmp != L"0")
			btnInfo.m_bTranparent = TRUE;
		
		strTmp = m_xml.GetChildAttrib(L"TCOLOR");
		btnInfo.m_clrTranparent = GetColorFromString(strTmp);

		strTmp = m_xml.GetChildAttrib(L"ICONNUM");
		btnInfo.m_nImgNum = _wtoi(strTmp.c_str());

		strTmp = m_xml.GetChildAttrib(L"BINTERVAL");
		btnInfo.m_bInterVal = _wtoi(strTmp.c_str())!=0;


		strTmp = m_xml.GetChildAttrib(L"INTDIGITNUM");
		btnInfo.m_nDigitCount = _wtoi(strTmp.c_str());

		strTmp = m_xml.GetChildAttrib(L"INTLZERO");
		btnInfo.m_bIntLeftZero = _wtoi(strTmp.c_str())!=0;

		strTmp = m_xml.GetChildAttrib(L"BDECLZERO");
		btnInfo.m_bDecLeftZero = _wtoi(strTmp.c_str())!=0;

		strTmp = m_xml.GetChildAttrib(L"DECDIGITNUM");
		btnInfo.m_nDecDigitCount = _wtoi(strTmp.c_str());

	}
	else
	{
		return FALSE;
	}

	return TRUE;
}

void CIResCfg::SetTimeNumParam(CTimeNumCtrl *pTimeNum,ITimeNumInfo &btnInfo)
{
	FONT_DECLARE;
	if(NULL == pTimeNum)
	{
		////RETAILMSG (APDEBUG, (TEXT("SetBtnParam failed invalide button handle!\r\n")));
	}

	HBITMAP hBitmap = CUtil::LoadBitmapEx( m_strResPath+ btnInfo.m_strImg,m_bFromDll);
	if(NULL == hBitmap)
	{
		////RETAILMSG (APDEBUG, (TEXT("SetBtnParam bitmap failed : %s!\r\n"),btnInfo.m_strImg));
	}
	pTimeNum->SetRect( btnInfo.m_rc );
	pTimeNum->SetIconNum(btnInfo.m_nImgNum);

	pTimeNum->SetBmp(hBitmap,btnInfo.m_bTranparent,btnInfo.m_clrTranparent);
	pTimeNum->SetBInterVal( btnInfo.m_bInterVal );

	pTimeNum->Set_INT_DigitCount( btnInfo.m_nDigitCount );
	pTimeNum->Set_INT_ShowleftZero( btnInfo.m_bIntLeftZero );

	pTimeNum->SetDecimalDigit( btnInfo.m_nDecDigitCount );
	pTimeNum->SetDecShowLZero( btnInfo.m_bDecLeftZero );

	pTimeNum->ReCalculatorRect( NULL );

}
BOOL CIResCfg::LoadIBmpNumParam(IBmpNumInfo &btnInfo,wstring strkey)
{
	m_xml.ResetMainPos();
	btnInfo.m_rc.SetRectEmpty();
	if(m_xml.FindChildElem(strkey))
	{
		wstring strTmp = m_xml.GetChildAttrib(L"IMAGE");
		if(!strTmp.length())
		{
			return FALSE;
		}
		else
		{
			btnInfo.m_strImg = strTmp;
		}

		strTmp = m_xml.GetChildAttrib(L"RECT");
		btnInfo.m_rc = GetRectFromString(strTmp);

		strTmp  = m_xml.GetChildAttrib(L"TOS");
		btnInfo.m_szTxtOffset = GetSizeFormString(strTmp);

		btnInfo.m_bTranparent = FALSE;
		strTmp  = m_xml.GetChildAttrib(L"BETRANS");
		if(strTmp != L"0")
			btnInfo.m_bTranparent = TRUE;
		
		strTmp = m_xml.GetChildAttrib(L"TCOLOR");
		btnInfo.m_clrTranparent = GetColorFromString(strTmp);


		strTmp = m_xml.GetChildAttrib(L"ICONNUM");
		btnInfo.m_nImgNum = _wtoi(strTmp.c_str());

		strTmp = m_xml.GetChildAttrib(L"DigitNum");
		btnInfo.m_nDigitCount = _wtoi(strTmp.c_str());

	}
	else
	{
		return FALSE;
	}

	return TRUE;
}

void CIResCfg::SetBmpNumParam(CNumberCtrl *pBmpNum,IBmpNumInfo &btnInfo)
{
	FONT_DECLARE;
	if(NULL == pBmpNum)
	{
		////RETAILMSG (APDEBUG, (TEXT("SetBtnParam failed invalide button handle!\r\n")));
	}

	HBITMAP hBitmap = CUtil::LoadBitmapEx( m_strResPath+ btnInfo.m_strImg,m_bFromDll);
	if(NULL == hBitmap)
	{
		////RETAILMSG (APDEBUG, (TEXT("SetBtnParam bitmap failed : %s!\r\n"),btnInfo.m_strImg));
	}
	pBmpNum->SetRect( btnInfo.m_rc );
	pBmpNum->SetTextOffset(btnInfo.m_szTxtOffset);
	pBmpNum->SetIconNum(btnInfo.m_nImgNum);

	pBmpNum->SetBmp(hBitmap,btnInfo.m_bTranparent,btnInfo.m_clrTranparent);

	pBmpNum->SetDigitCount( btnInfo.m_nDigitCount );
	pBmpNum->ReCalculatorRect( NULL );
}

BOOL   CIResCfg::LoadIAlpNumInfo( IAlpNumInfo &info,wstring strkey )
{
	m_xml.ResetMainPos();
	info.m_rc.SetRectEmpty();

	if(m_xml.FindChildElem(strkey))
	{
		info.m_strImg0		= m_xml.GetChildAttrib(L"IMAGE0");
		info.m_strImg1		= m_xml.GetChildAttrib(L"IMAGE1");
		info.m_strImg2		= m_xml.GetChildAttrib(L"IMAGE2");
		info.m_strImg3		= m_xml.GetChildAttrib(L"IMAGE3");
		info.m_strImg4		= m_xml.GetChildAttrib(L"IMAGE4");
		info.m_strImg5		= m_xml.GetChildAttrib(L"IMAGE5");
		info.m_strImg6		= m_xml.GetChildAttrib(L"IMAGE6");
		info.m_strImg7		= m_xml.GetChildAttrib(L"IMAGE7");
		info.m_strImg8		= m_xml.GetChildAttrib(L"IMAGE8");
		info.m_strImg9		= m_xml.GetChildAttrib(L"IMAGE9");
		info.m_strImgInterVal = m_xml.GetChildAttrib(L"IMAGE_INTV");


		wstring strTmp = m_xml.GetChildAttrib(L"RECT");
		info.m_rc = GetRectFromString(strTmp);

		info.m_bLeftZero = FALSE;
		strTmp  = m_xml.GetChildAttrib(L"BLEFTZERO");
		if(strTmp != L"0")
			info.m_bLeftZero = TRUE;

		info.m_bInterVal = FALSE;
		strTmp  = m_xml.GetChildAttrib(L"BINTERVAL");
		if(strTmp != L"0")
			info.m_bInterVal = TRUE;

		strTmp  = m_xml.GetChildAttrib(L"SIZE");
		info.m_szOneNum = GetSizeFormString(strTmp);

		strTmp = m_xml.GetChildAttrib(L"ICONNUM");
		info.m_nImgNum = _wtoi(strTmp.c_str());

		strTmp = m_xml.GetChildAttrib(L"LEFTDIGIT");
		info.m_nLeftDigitCount = _wtoi(strTmp.c_str());

		strTmp = m_xml.GetChildAttrib(L"RIGHTDIGIT");
		info.m_nRightDigitCount = _wtoi(strTmp.c_str());

	}
	else
	{
		return FALSE;
	}

	return FALSE;
}

void  CIResCfg::SetAlpNumInfo( CFAlpNumCtrl *pBmpNum,IAlpNumInfo &Info,CMyUnCompress* pPack )
{
	wstring strResBak = m_strResPath;
	if ( pPack==NULL )
		m_strResPath = CUtil::GetResPath() + m_strResPath;
	
	pBmpNum->LoadStateRes( m_strResPath+Info.m_strImg0,NUM_ZERO, pPack );
	pBmpNum->LoadStateRes( m_strResPath+Info.m_strImg1,NUM_ONE, pPack );
	pBmpNum->LoadStateRes( m_strResPath+Info.m_strImg2,NUM_TWO, pPack );
	pBmpNum->LoadStateRes( m_strResPath+Info.m_strImg3,NUM_THREE, pPack );
	pBmpNum->LoadStateRes( m_strResPath+Info.m_strImg4,NUM_FOUR, pPack );
	pBmpNum->LoadStateRes( m_strResPath+Info.m_strImg5,NUM_FIVE, pPack );
	pBmpNum->LoadStateRes( m_strResPath+Info.m_strImg6,NUM_SIX, pPack );
	pBmpNum->LoadStateRes( m_strResPath+Info.m_strImg7,NUM_SEVEN, pPack );
	pBmpNum->LoadStateRes( m_strResPath+Info.m_strImg8,NUM_EIGHT, pPack );
	pBmpNum->LoadStateRes( m_strResPath+Info.m_strImg9,NUM_NINE, pPack );
	pBmpNum->LoadStateRes( m_strResPath+Info.m_strImgInterVal,NUM_INTERVAL, pPack );

	if ( pPack==NULL )
		m_strResPath = strResBak;



	pBmpNum->SetRect( Info.m_rc );
	pBmpNum->SetShowleftZero( Info.m_bLeftZero );
	pBmpNum->SetbInterVal( Info.m_bInterVal  );
	pBmpNum->SetOneNumSize( Info.m_szOneNum  );

	pBmpNum->SetDigitCount( Info.m_nLeftDigitCount,Info.m_nRightDigitCount  );
	pBmpNum->ReCalculatorRect( NULL );

}